package cn.edu.seu.ssny.service.impl;

import cn.edu.seu.ssny.dao.IEquipmentTypeDao;
import cn.edu.seu.ssny.dao.IEquipmentTypeInProjectDao;
import cn.edu.seu.ssny.dao.support.IBaseDao;
import cn.edu.seu.ssny.entity.EquipmentType;
import cn.edu.seu.ssny.entity.EquipmentTypeInProject;
import cn.edu.seu.ssny.entity.Project;
import cn.edu.seu.ssny.service.IEquipmentTypeInProjectService;
import cn.edu.seu.ssny.service.IEquipmentTypeService;
import cn.edu.seu.ssny.service.support.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * 设备表
 */
@Service
public class EquipmentTypeInProjectServiceImpl extends BaseServiceImpl<EquipmentTypeInProject, Integer> implements IEquipmentTypeInProjectService {

    @Autowired
    private IEquipmentTypeInProjectDao equipmentTypeInProjectDao;

    @Override
    public IBaseDao<EquipmentTypeInProject, Integer> getBaseDao() {
        return this.equipmentTypeInProjectDao;
    }

    @Override
    public Optional<EquipmentTypeInProject> findByProjectAndTypeName(Project project, EquipmentType equipmentType) {
        return equipmentTypeInProjectDao.findByProjectAndTypeName(project, equipmentType);
    }

    @Override
    public List<EquipmentTypeInProject> findByProject(Project project) {
        return equipmentTypeInProjectDao.findByProjectOrderByTypeNameName(project);
    }

    @Override
    public void create(Project project, EquipmentType equipmentType) {
        EquipmentTypeInProject typeInProject = new EquipmentTypeInProject();
        typeInProject.setProject(project);
        typeInProject.setTypeName(equipmentType);
        saveAndFlush(typeInProject);
    }
}